package com.wxy.demo.thread_pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 线程池
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2022/9/22 18:30
 */
public class Demo {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            pool.submit(() -> {
                Thread t = Thread.currentThread();
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程休眠完成：" + t.getName());
                t.stop();
                System.out.println("线程停止：" + t.getName());
            });
        }
    }
}
